$(function () {
    GetArticle();

})

//首页 上一页 文章列表
function GetPreviousArticle() {
    var next_url = $('#the_previous').attr('value')
    // console.log(next_url)
    $.ajax({
        url: next_url,
        method: "get",
        // data: {ordering:'-update_time', page: '1', page_size: '5'},
        contentType: "application/json",
        xhrFields: {
            withCredentials: true
        },
        success: function (resp) {
            var res_data = eval(resp);
            // console.log(res_data);
            $('#the_next').attr('value',res_data.next);
            $('#the_previous').attr('value',res_data.previous);
            html = '';
            for (var i in res_data.results){
                // console.log(res_data.results[i])
                html +=
                    '<div class="blog-post sidebar-module-inset wow bounceIn" style="margin-top: 15px;">' +
                        '<h2 class="blog-post-title"><a href="../html/article_detail.html?' + res_data.results[i].id +'">' + res_data.results[i].article_name + '</a></h2>' +
                        '<p class="blog-post-meta">' + res_data.results[i].update_time.substring(0,16) + '  <a href="./user_detail.html?' + res_data.results[i].users_id +'">' + res_data.results[i].users_id + '</a></p>' +
                        // '<div class="us-post-img hidden">' +
                        //     '<a href=""><img src="../images/big001.jpg"></a>' +
                        // '</div>' +
                        // '<div class="us-post-img">' +
                        //     '<a href=""><img src="../images/big001.jpg"></a>' +
                        // '</div>' +
                        '<p>' + res_data.results[i].article_text.substring(0,120) + '</p>' +
                        '<div>' +
                            '<a href="../html/article_detail.html?' + res_data.results[i].id +'" class="btn btn-default us-post-link">阅读全文</a>' +
                        '</div>' +
                    '</div>'
                $("#get_all_article").html(html)

            }


        },
        error: function (resp) {

        }
    })
}




//首页下一页文章列表
function GetNextArticle() {
    var next_url = $('#the_next').attr('value')
    $.ajax({
        url: next_url,
        method: "get",
        // data: {ordering:'-update_time', page: '1', page_size: '5'},
        contentType: "application/json",
        xhrFields: {
            withCredentials: true
        },
        success: function (resp) {
            var res_data = eval(resp);
            // console.log(res_data);
            $('#the_next').attr('value',res_data.next);
            $('#the_previous').attr('value',res_data.previous);
            html = '';
            for (var i in res_data.results){
                // console.log(res_data.results[i])
                html +=
                    '<div class="blog-post sidebar-module-inset wow bounceIn" style="margin-top: 15px;">' +
                        '<h2 class="blog-post-title"><a href="../html/article_detail.html?' + res_data.results[i].id +'">' + res_data.results[i].article_name + '</a></h2>' +
                        '<p class="blog-post-meta">' + res_data.results[i].update_time.substring(0,16) + '  <a href="./user_detail.html?' + res_data.results[i].users_id +'">' + res_data.results[i].users_id + '</a></p>' +
                        // '<div class="us-post-img hidden">' +
                        //     '<a href=""><img src="../images/big001.jpg"></a>' +
                        // '</div>' +
                        // '<div class="us-post-img">' +
                        //     '<a href=""><img src="../images/big001.jpg"></a>' +
                        // '</div>' +
                        '<p>' + res_data.results[i].article_text.substring(0,120) + '</p>' +
                        '<div>' +
                            '<a href="../html/article_detail.html?' + res_data.results[i].id +'" class="btn btn-default us-post-link">阅读全文</a>' +
                        '</div>' +
                    '</div>'
                $("#get_all_article").html(html)

            }


        },
        error: function (resp) {

        }
    })
}



//首页获得文章列表
function GetArticle() {
    $.ajax({
        url: host + "/get_article/",
        method: "get",
        data: {ordering:'-update_time', page: '1', page_size: '5'},
        contentType: "application/json",
        xhrFields: {
            withCredentials: true
        },
        success: function (resp) {
            var res_data = eval(resp);
            // console.log(res_data);
            $('#the_next').attr('value',res_data.next);
            $('#the_previous').attr('value',res_data.previous);
            html = '';
            for (var i in res_data.results){
                // console.log(res_data.results[i])
                html +=
                    '<div class="blog-post sidebar-module-inset wow bounceIn" style="margin-top: 15px;">' +
                        '<h2 class="blog-post-title"><a href="../html/article_detail.html?' + res_data.results[i].id +'">' + res_data.results[i].article_name + '</a></h2>' +
                        '<p class="blog-post-meta">' + res_data.results[i].update_time.substring(0,16) + '  <a href="./user_detail.html?' + res_data.results[i].users_id +'">' + res_data.results[i].users_id + '</a></p>' +
                        // '<div class="us-post-img hidden">' +
                        //     '<a href=""><img src="../images/big001.jpg"></a>' +
                        // '</div>' +
                        // '<div class="us-post-img">' +
                        //     '<a href=""><img src="../images/big001.jpg"></a>' +
                        // '</div>' +
                        '<p>' + res_data.results[i].article_text.substring(0,120) + '</p>' +
                        '<div>' +
                            '<a href="../html/article_detail.html?' + res_data.results[i].id +'" class="btn btn-default us-post-link">阅读全文</a>' +
                        '</div>' +
                    '</div>'
                $("#get_all_article").html(html)

            }


        },
        error: function (resp) {

        }
    })
}